<?php

function viewnewmessages($member_id){
 
// opening the connection
 $conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
                 mysql_select_db('mydb') or die(mysql_error());
                 //getting the memberid

// retrieveing the message id
$query1 = mysql_query("
SELECT m.`message_id`
FROM  `messages`m INNER JOIN `member_message_member` mm ON m.`message_id`= mm.`message_id`
WHERE mm.`member_id2` = '$member_id' AND m.`seen`=0") or die(mysql_error());
//adding a count variable to know how many new messages he has
$count= 0;
// looping over the messages 
while ($row5 = mysql_fetch_array($query1)) {
    
    $count++;  
}
//adding a link to redirect him to the inbox
if ($count>=1){
    echo"
<td><a href='viewmessages.php'> You have {$count} new messages  </a></td>
</tr>";
}
else {
return;
}
mysql_close($conn);
}



?>


